#include<iostream>
#include<fstream>
using namespace std;
#define ERROR 0

typedef struct LNode //定义单链表
{
	int data;
	struct LNode *next;
} LNode, *LinkList;

int num_a, num_b;


void InitList_L(LinkList &L) //创建单链表
{
	L = new LNode;
	L->next = NULL;
}

void input(LinkList &L, int n) //依次往单链表L里输入数据
{
	/********************************************Begin******************************/
    LNode *T = L;
    while(n--)
    {
        LNode *p = new LNode;
        cin >> p->data;
        p->next = T->next;
        T->next = p;
        T = p;
    }

    /*******************************************End*******************************/

}

void output(LinkList L) //依次输出单链表里的每个元素
{
	int i = 0;
	LNode *p;
	p = L->next;
	while (p) {
		if (i)
			cout << ",";
		cout << p->data;
		p = p->next;
		i = 1;
	}
}

void MergeList_L(LinkList &LA, LinkList &LB, LinkList &LC) //算法2.17 链式有序表的合并
{
	//已知单链表LA和LB的元素按值非递减排列
	//归并LA和LB得到新的单链表LC，LC的元素也按值非递减排列
	/********************************Begin*****************************************/
    LNode *pa = LA->next, *pb = LB->next, *T = LC;
    while(pa && pb)
    {
        if(pa->data < pb->data)
        {
            LNode *q = pa;
            pa = pa->next;
            q->next = T;
            T->next = q;
            T = q;
        }
        else
        {
            LNode *q = pb;
            pb = pb->next;
            q->next = T;
            T->next = q;
            T = q;
        }
    }
    T->next = pa ? pa : pb;

    /*********************************End****************************************/
} //MergeList_L()

int main() {
	LinkList La, Lb, Lc;
	
	scanf("%d %d", &num_a, &num_b);
	
	InitList_L(La); //La表的创建
	input(La, num_a); //依次往单链表La里输入数据

	InitList_L(Lb); //Lb表的创建	
	input(Lb, num_b); //依次往单链表La里输入数据

	InitList_L(Lc);
	MergeList_L(La, Lb, Lc); //将单链表La和Lb进行合并

	output(Lc);
	cout << endl;
	return 0;
}